<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <!-- 
        js示例图步骤:
        1.引入外部链接
        2.定义一个宽高div
        3.初始化echarts实例 init(){echarts.init(this.$refs.main);}
        4.配置图表数据（var option = {} --data: {name: "",count: "",xData: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],serieData: [5, 20, 36, 10, 10, 20],},
        5.使用配置项和图标（myChart.setOption(option);
        6. dom挂载完毕--mounted() {this.init();},
     -->
    <div id="app">
      <!-- 画布 -->
      <!-- <canvas></canvas> -->

      <p>名称: <input v-model="name" type="text" /></p>
      <p>数量: <input v-model.number="count" type="text" /></p>
      <p>
        <button @click="addItem">添加</button>
      </p>
      <div ref="main" style="width: 600px; height: 400px"></div>
    </div>

    <script
      crossorigin="anonymous"
      integrity="sha512-CNXD81ugRg68yNQQ9TSlZb/pLzbJ5Xo+QRQhIKxW7U3wwYOTcb9O0Q+3yWiWvwBElV/z7oo0hlqOqxPyMbZ8zQ=="
      src="https://lib.baomitu.com/echarts/5.3.3/echarts.common.js"
    ></script>
    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          name: "",
          count: "",
          xData: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
          serieData: [5, 20, 36, 10, 10, 20],
        },
        methods: {
          // 初始化
          init() {
            var myChart = echarts.init(this.$refs.main);
            // 指定图表的配置项和数据
            var option = {
              title: {
                text: "ECharts 入门示例",
              },
              tooltip: {},
              legend: {
                data: ["销量"],
              },
              xAxis: {
                data: this.xData,
              },
              yAxis: {},
              series: [
                {
                  name: "销量",
                  type: "bar",
                  data: this.serieData,
                },
              ],
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
          },
          // 添加
          addItem() {
            this.xData.push(this.name);
            this.serieData.push(this.count);
            this.init();
          },
        },
        // dom挂载完毕
        mounted() {
          this.init();
        },
      });
    </script>
  </body>
</html>
